<template>
  <page-header-wrapper>
    <application-search @search="handleSearch" @reset="handleReset"> </application-search>
    <a-card :bordered="false">
      <div class="table-header m-b-24"></div>
      <s-table
        ref="table"
        size="default"
        rowKey="ID"
        :columns="columns"
        :data="loadData"
        :scroll="{ x: true }"
        :pagination="{ showTotal: (total) => `共 ${total} 条` }"
      >
        <span slot="index" slot-scope="text, record, index">{{ index + 1 }} </span>
        <div slot="action" slot-scope="text, record">
          <y-button type="link" @click="handleDetail(record.ID)">查看</y-button>
        </div>
      </s-table>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { STable, Ellipsis, buttonSelect, applicationSearch } from '@/components'
import { getDistributionManagement } from '@/api/DistrictReviewReportManagement'
import moment from 'moment'
export default {
  name: 'cityComplexInquireList',
  components: {
    STable,
    Ellipsis,
    buttonSelect,
    applicationSearch,
  },
  data() {
    return {
      queryParam: {
        Mode: 'FenLedger',
        strContent: {},
      },
      columns: [
        {
          title: '序号',
          align: 'center',
          width: 80,
          fixed: 'left',
          scopedSlots: { customRender: 'index' },
        },
        {
          title: '申请人',
          align: 'center',
          fixed: 'left',
          dataIndex: 'Proposer',
        },
        {
          title: '身份证号',
          align: 'center',
          fixed: 'left',
          dataIndex: 'IDCard',
        },
        {
          title: '联系电话',
          align: 'center',
          dataIndex: 'Phone',
        },
        {
          title: '剩余时间',
          align: 'center',
          dataIndex: 'ESetDate',
          customRender: (text) => {
            if (this.$isEmpty(text)) {
              return <span class="text-warning">数据残缺，请核对数据</span>
            } else {
              const diffDay = moment().diff(moment(text), 'days')
              const resultDay = 30 - diffDay
              if (resultDay >= 0) {
                return <span class="text-success">还剩{resultDay}天</span>
              } else {
                return <span class="text-error">已经超期{resultDay * -1}天</span>
              }
            }
          },
        },
        {
          title: '安置点',
          align: 'center',
          dataIndex: 'Esites',
        },
        {
          title: '项目名称',
          align: 'center',
          dataIndex: 'Name',
        },
        {
          title: '区域',
          align: 'center',
          dataIndex: 'RegionName',
          customRender: (text) => <ellipsis length={16}>{text}</ellipsis>,
        },
        {
          title: '社区服务中心',
          align: 'center',
          dataIndex: 'TownshipName',
          customRender: (text) => <ellipsis length={16}>{text}</ellipsis>,
        },
        {
          title: '户型',
          align: 'center',
          dataIndex: 'Structure',
        },
        {
          title: '房屋号',
          align: 'center',
          customRender: (text, record) => {
            return `${record.Roof}栋${record.Unit}单元${record.Floor}-${record.Number}`
          },
        },
        {
          title: '分配时间',
          align: 'center',
          customRender: (test, record) => (record.ESetDate ? moment(record.ESetDate).format('YYYY-MM-DD') : '/'),
        },
        {
          title: '操作时间',
          align: 'center',
          customRender: (test, record) => (record.ESetDate ? moment(record.ESetDate).format('YYYY-MM-DD') : '/'),
        },
        {
          title: '分配人',
          align: 'center',
          dataIndex: 'EsitesPerson',
          customRender: (text) => text || '/',
        },
        {
          title: '操作',
          align: 'center',
          width: '80px',
          fixed: 'right',
          scopedSlots: { customRender: 'action' },
        },
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return getDistributionManagement(requestParameters).then((res) => res)
      },
    }
  },
  methods: {
    handleSearch(values) {
      this.queryParam.strContent = values
      this.tableRefresh(true)
    },
    handleReset() {
      this.queryParam.strContent = {}
      this.tableRefresh(true)
    },
    tableRefresh(refresh = false) {
      this.$refs.table.refresh(refresh)
    },
    handleDetail(id) {
      localStorage.setItem('browserCacheDetail', JSON.stringify({ id: id }))
      this.$router.push({
        name: 'DistriButionAccountDetail',
        params: {
          id,
        },
      })
    },
  },
}
</script>
<style lang="less" scoped>
/deep/ .ant-table td {
  white-space: nowrap;
}
</style>
